home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
10 - Networking
/
NovelNetwar
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-12
|
5KB
|
276 lines
// The main routine!
#include "NovelNetwar.h"
static WindowPtr lastFront = 0L;
static void InitToolbox(void);
static void ChooseConnectionMethod(void);
main()
{
EventRecord theEvent;
char theChar;
Point thePt;
OSErr errCode;
int i;
InitToolbox();
globalsInit();
appleEventsInit();
cursorsInit();
windowsInit();
helpInit();
menusInit();
gameplayInit();
appletalkingInit();
serialInit();
ChooseConnectionMethod();
globalsStartup();
appleEventsStartup();
cursorsStartup();
helpStartup();
windowsStartup();
menusStartup();
gameplayStartup();
appletalkingStartup();
serialStartup();
if (connectionMethod == SERIAL)
{
errCode = serialConnectToOpponents();
if (errCode != noErr)
{
ErrorAlert(errorMessage);
}
}
else if (connectionMethod == APPLETALK)
{
errCode = appleTalkingConnectToOpponents();
if (errCode != noErr)
{
ErrorAlert(errorMessage);
}
}
while (alive)
{
if (IAmFrontApp == true)
{
GetMouse(&thePt);
cursorsMaintainCursor(thePt);
gameplayIdle();
}
if (CapsLock() == false)
{
WaitNextEvent(everyEvent,&theEvent,0L,0L);
switch (theEvent.what)
{
case mouseDown:
DoMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
theChar = theEvent.message & charCodeMask;
if (theEvent.modifiers & cmdKey)
{
DoCommand(MenuKey(theChar));
}
ObscureCursor();
break;
case activateEvt:
if (IsOurWindow((WindowPtr) theEvent.message) == noErr)
{
if (!(theEvent.modifiers & activeFlag))
lastFront = (WindowPtr) theEvent.message;
DoActivateDeactivate((WindowPtr) theEvent.message,(char) (theEvent.modifiers & activeFlag));
}
break;
case updateEvt:
if (IsOurWindow((WindowPtr) theEvent.message) == noErr)
UpdateWindow((WindowPtr) theEvent.message);
break;
case osEvt:
theChar = (theEvent.message & 0xFF000000) >> 24;
if (theChar == suspendResumeMessage)
{
if (theEvent.message & 0x01) /* resume */
{
if (IsOurWindow(lastFront) == noErr)
{
IAmFrontApp = true;
DoActivateDeactivate(lastFront,true);
}
}
else /* suspend */
{
if (IsOurWindow((WindowPtr) FrontWindow()) == noErr)
{
lastFront = (WindowPtr) FrontWindow();
IAmFrontApp = false;
DoActivateDeactivate(lastFront,false);
InitCursor();
}
}
}
break;
}
}
}
DoShutDown();
return(0);
}
static void InitToolbox(void)
{
InitGraf((Ptr) &qd.thePort);
InitFonts();
InitWindows();
InitMenus();
FlushEvents(everyEvent,0);
TEInit();
InitDialogs(0L);
InitCursor();
}
static void ChooseConnectionMethod(void)
{
DialogPtr theDPtr,tempDPtr;
short itemHit, type;
Handle theItem;
Rect tempRect;
GrafPtr oldPort;
char tempString[256];
EventRecord theEvent;
GetPort(&oldPort);
InitCursor();
if (!(theDPtr = GetNewDialog(CHOOSEMETHODDLOG, nil,(WindowPtr) -1L)))
{
FatalError("Can't allocate memory for Choose Connection Method dialog....");
}
SetPort(theDPtr);
CenterWindow(theDPtr);
ShowWindow(theDPtr);
((DialogPeek) theDPtr)->aDefItem = 4;
GetDItem(theDPtr, 5, &type, &theItem, &tempRect);
SetDItem(theDPtr, 5, type,(Handle) HiliteDefaultButton, &tempRect);
GetDItem(theDPtr, 2, &type, &theItem, &tempRect);
SetControlValue((ControlHandle) theItem,0);
GetDItem(theDPtr, 3, &type, &theItem, &tempRect);
SetControlValue((ControlHandle) theItem,0);
do
{
ModalDialog((ModalFilterProcPtr) MyFilter,&itemHit);
if (itemHit == 3)
{
if (connectionMethod != SERIAL)
{
connectionMethod = SERIAL;
GetDItem(theDPtr, 3, &type, &theItem, &tempRect);
SetControlValue((ControlHandle) theItem,1);
GetDItem(theDPtr, 2, &type, &theItem, &tempRect);
SetControlValue((ControlHandle) theItem,0);
}
}
else if (itemHit == 2)
{
if (connectionMethod != APPLETALK)
{
connectionMethod = APPLETALK;
GetDItem(theDPtr, 3, &type, &theItem, &tempRect);
SetControlValue((ControlHandle) theItem,0);
GetDItem(theDPtr, 2, &type, &theItem, &tempRect);
SetControlValue((ControlHandle) theItem,1);
}
}
} while (itemHit != 4);
DisposDialog(theDPtr);
SetPort(oldPort);
}
void DoShutDown(void)
{
serialShutdown();
appletalkingShutdown();
gameplayShutdown();
windowsShutDown();
menusShutDown();
cursorsShutDown();
helpShutDown();
appleEventsShutDown();
globalsShutDown();
}